﻿using KZ.Express.ENT;
using KZ.Express.Resource;
using KZ.Express.Task;
using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.Data;

namespace KZ.Express.Presenter
{
    public class CustomerGroupPresenter : PresenterBase
    {
        private new CustomerGroupTask _task;

        public CustomerGroupPresenter(IViewBase view)
            : base(view, new PartnerGroupENT())
        {
            _view = view;
            _task = new CustomerGroupTask();
        }

        public override void LoadDataTable()
        {
            try
            {
                _view.SetMessage(String.Empty, true);
                DataTable dt = _task.LoadDataTable(_view.Search);
                DataRow row = dt.NewRow();
                dt.Rows.Add(row);

                _view.Table = dt;
            }
            catch (DataAccessException ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }

        public void Save(List<DataRow> rows)
        {
            try
            {
                _task.Save(rows);
                LoadDataTable();
                _view.SetMessage(Message.BLM_SUC_SAVE.ToString(), true);
            }
            catch (DataAccessException ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }
    }
}